package digitCount;

import java.util.Scanner;
import java.util.HashMap;


public class DigitCount {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个7位以内的数字：");
        String input = scanner.next();

        if (input.length() > 7 || input.isEmpty()) {
            System.out.println("invalid input");
            return;
        }

        HashMap<Character, Integer> digitCount = new HashMap<>();

        for (char digit : input.toCharArray()) {
            if (!digitCount.containsKey(digit)) {
                digitCount.put(digit, 1);
            } else {
                digitCount.put(digit, digitCount.get(digit) + 1);
            }
        }

        System.out.println("各位数出现的次数为：");
        for (Character i : digitCount.keySet()) {
            System.out.println("key: " + i + " value: " + digitCount.get(i));//i会自动拆包
        }

        scanner.close();
    }
}
